<%@ page import="java.util.LinkedList" %>
<%@ page import="java.util.Date" %><%--
  Created by IntelliJ IDEA.
  User: user
  Date: 2025/3/21
  Time: 9:53
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
    <title>JSTL标签库的讲解</title>
</head>
<body>
<%
    request.setAttribute("username","tom");
    LinkedList ls=new LinkedList();
    ls.add("张三");
    ls.add("李四");
    ls.add("王五");
    session.setAttribute("lsdata",ls);
%>
<%--out标签的用法--%>
您好！<c:out value="${requestScope.username}" default="游客"></c:out>
<%--if标签的用法，相当于单分支，满足条件后执行，不满足条件跳过--%>
<br/>
<c:if test="${not empty requestScope.username}">
    你好，${requestScope.username}
</c:if>

<%--choose标签的用法，相当于if -else的用法--%>
<br/>
<c:choose>
    <c:when test="${not empty sessionScope.username}">
        你好，${sessionScope.username}
    </c:when>
    <c:otherwise>
        你好，游客
    </c:otherwise>
</c:choose>

<%--foreach标签的用法--%>
<br/>
<c:forEach items="${sessionScope.lsdata}" var="eachData" varStatus="status">
    ${status.index+1}：${eachData}；
</c:forEach>
<br/>
<%--求100以内的奇数--%>
<c:forEach begin="1" end="100" step="2" var="num">
    ${num}
</c:forEach>
<br/>
<%--使用foreach标签实现九九乘法表--%>
<c:forEach begin="1" end="9" var="i">
    <c:forEach begin="1" end="${i}" var="j">
        ${j}*${i}=${i*j} &nbsp;
    </c:forEach>
    <br/>
</c:forEach>
<%--将当前日期格式化处理--%>
<fmt:formatDate value="<%=new Date()%>" pattern="yyyy-MM-dd HH:mm:ss"></fmt:formatDate>
</body>
</html>
